package com.xtkj.superclub_share.controller;

import com.xtkj.commons.JsonResult;
import com.xtkj.commons.TokenUtil;
import com.xtkj.superclub_entity.entity.user.User;
import com.xtkj.superclub_share.client.IUserClient;
import com.xtkj.superclub_share.service.IShareService;
import jdk.nashorn.internal.parser.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lizheqi
 * @create 2019-12-31-16:01
 */
@RestController
@RequestMapping("/invite")
public class InviteController {

    @Autowired
    private IUserClient userClient;
    /**
     * 邀请好友注册
     * @return
     */
    public JsonResult listInvites(@RequestBody User user,HttpServletRequest request) {
        //通过前端传过来的用户的电话与数据库进行比较，有则可以复制链接给对方
       try {
           JsonResult json = userClient.inviteUser(user);
           //如果获取到用户
           if(json.getData()!=null){
               //获取该请求的链接地址
               StringBuffer requestURL = request.getRequestURL();
               return JsonResult.success().setMsg("邀请成功").setData(requestURL).setCode(200);
           }
           return JsonResult.success().setMsg("不能邀请");
       }catch (Exception e){
           return JsonResult.error().setMsg("邀请失败").setCode(400);
       }
    }


}
